6 February 2019

Introduction

This presentation features creation of the interactive plots using Plotly as a part of the exploratory data analysis of the dataset ToothGrowth in R.

Procedures to be done

  • We load the library with the dataset of interest using the following command
library(datasets)
data(ToothGrowth)
  • We look into the structure of the dataset
library(dplyr)
str(ToothGrowth)
ToothGrowth$dose<-as.factor(ToothGrowth$dose)
summary(ToothGrowth)

  • We use Plotly to perform exploratory data analysis
library(plotly)
# histogram of the tooth length
plot_ly(x=ToothGrowth$len, type="histogram")
# boxplots of the tooth length by the type of supplements
plot1<-ggplot(data=ToothGrowth,aes(x = supp, y = len))+
      geom_boxplot(aes(fill=supp))
(gg<-ggplotly(plot1))
# boxplots of the tooth length by the type of supplements and the dose
plot2<-ggplot(data=ToothGrowth,aes(x = supp, y = len))+
      geom_boxplot(aes(fill=supp)) + facet_wrap(~ dose)
(gg<-ggplotly(plot2))

Structure of the dataset

library(dplyr)
str(ToothGrowth)
## 'data.frame':    60 obs. of  3 variables:
##  $ len : num  4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
##  $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
##  $ dose: num  0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
ToothGrowth$dose<-as.factor(ToothGrowth$dose)
summary(ToothGrowth)
##       len        supp     dose   
##  Min.   : 4.20   OJ:30   0.5:20  
##  1st Qu.:13.07   VC:30   1  :20  
##  Median :19.25           2  :20  
##  Mean   :18.81                   
##  3rd Qu.:25.27                   
##  Max.   :33.90

The histogram

library(plotly)
# histogram of the tooth length
plot_ly(x=ToothGrowth$len, type="histogram")

The boxplot by the type of supplement

The boxplot by the type of supplement and the dose

Thank you for the review!